package com.kingdee.pda.ui.query_replenish_order;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.ReplenishOrderBean;

import java.util.HashMap;
import java.util.List;

/**
 * @author：dlj
 * @data：2021/6/30:17:31
 * @des：补货单查询Presenter
 */
public class QueryRepleOrderPresenter implements QueryReplenishOrderContract.IQueryRepleOrderPresenter {
    private Context context;
    private QueryReplenishOrderContract.IQueryOrderView view;

    public QueryRepleOrderPresenter() {
    }

    public QueryRepleOrderPresenter(Context context, QueryReplenishOrderContract.IQueryOrderView view) {
        this.context = context;
        this.view = view;
    }

    @Override
    public void queryReplenishOrderList(String status, String billNo, long warehouseId, int pageSize, int pageIndex) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("warehouseId", warehouseId);
        map.put("pageSize", pageSize);
        map.put("pageIndex", pageIndex);
        map.put("billStatus", status);
        map.put("billNo", billNo);
        map.put("itemSkucode", billNo);

        MyObserver<List<ReplenishOrderBean.DataBean>> myObserver = new MyObserver<List<ReplenishOrderBean.DataBean>>(context) {
            @Override
            public void onSuccess(BaseResponse<List<ReplenishOrderBean.DataBean>> result) {
                view.onGetOrderSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result,String msg) {
                view.onGetOrderFailed(msg);
            }
        };
        HttpUtils.request(Api.class)
                .getRepleOrderList(ConstantUtil.REPLEORDER_GETLIST, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
